/**
 * 图片格式:jpg、png、jpeg、gif 录音格式:wav、amr、awb 视频格式:3gp、mp4、rmvb、avi、flv
 * 文档格式:doc、docx、txt、pdf、excel
 */
function checkFileFormat(tempVal, flagKey) {
	if (tempVal != "" && flagKey != "") {
		// 扩展名获取
		var extension = tempVal.substring(
				parseInt(tempVal.lastIndexOf('.')) + 1, tempVal.length);
		extension = extension.toLowerCase();
		if (flagKey == "photo") {
			if (extension == "jpg" || extension == "png" || extension == "jpeg"
					|| extension == "gif") {
				return true;
			} else {
				alert("请选择图片文件,支持格式：jpg,png,jpeg,gif!");
				return false;
			}
		}
		if (flagKey == "ly") {
			if (extension == "wav" || extension == "amr" || extension == "awb"
					|| extension == "mp3") {
				return true;
			} else {
				alert("请选择格音文件,支持格式：wav,amr,awb,mp3!");
				return false;
			}
		}
		if (flagKey == "video") {
			if (extension == "3gp" || extension == "mp4" || extension == "rmvb"
					|| extension == "avi" || extension == "flv") {
				return true;
			} else {
				alert("请选择视频文件,支持格式：3gp,mp4,rmvb,avi,flv!");
				return false;
			}
		}
		if (flagKey == "document") {
			if (extension == "doc" || extension == "docx" || extension == "txt"
					|| extension == "pdf" || extension == "xls"
					|| extension == "xlsx") {
				return true;
			} else {
				alert("请选择文档文件,支持格式：doc,docx,txt,pdf,xls,xlsx!");
				return false;
			}
		}
	}
	return false;
}
/**
 * 去空
 */
function trim(option) {
	return option.replace(/ /g, '');
}

/**
 * 截取filename中的文件名
 */
/*
 * function getFileName(option){ var str = option; alert(str); if(str!=undefined &&
 * str!=""){ return str.substring(str.lastIndexOf('\\')+1,str.length); }else{
 * return false; } }
 */
/**
 * 表单验证：验证是否是身份证号码
 */
function checkIdentity(inputObj) {
	var inputValue = inputObj.value;
	if (inputValue == "" || inputValue == "身份证号码格式不正确!") {
		$(inputObj).css("color", "red");
		$(inputObj).val("身份证号码格式不正确!");
		inputObj.focus();
		return false;
	}
	var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
	if (reg.test(inputValue) == false) {
		$(inputObj).css("color", "red");
		$(inputObj).val("身份证号码格式不正确!");
		inputObj.focus();
		return false;
	} else {
		$(inputObj).css("color", "black");
		return true;
	}
}

/**
 * 鼠标移动上去对象被选中,并全选
 */
function reFocus(obj) {
	var val = obj.value;
	if (val == "身份证号码格式不正确!" || val == "手机号码格式不正确!") {
		$(obj).focus();
		$(obj).select();
		$(obj).css("color", "black");
	}
}

/**
 * 起始日期 与 截止日期比较
 * 
 * @param date1
 * @param date2
 * @param compare
 * @returns {Boolean}
 */
function checkTwoDate(date1, date2, compare) {
	var date1Value = date1.replace("-", "/");
	var date2Value = date2.replace("-", "/");
	try {
		var date1Date = new Date(date1Value);
		var date2Date = new Date(date2Value);
		if (compare == true) {
			if (date1Date >= date2Date) {
				alert("开始日期不能大于等于结束日期!");
				return false;
			}
		}
		return true;
	} catch (e) {
		alert("日期格式有误!")
		return false;
	}
}

/**
 */
function checkDataType(inputObj) {
	var inputValue = inputObj.value;
	if (inputValue != "") {
		if (isNaN(inputValue)) {
			alert("请输入数字！");
			inputObj.value = "";
			inputObj.focus();
			return false;
		}
	}
	return true;
}

function checkLengthTwo(length1, length2, obj, label) {
	var length = obj.value.length;
	if (length != 0 && length != length2 && length != length1) {
		if (label == null) {
			label = "";
		}
		obj.focus();
		$(obj).css("color", "red");
		$(obj).val(label + "的字符长度必须为 " + length1 + " 或 " + length2);
		return;
	}
}

/**
 * 验证联系电话
 * 
 * @param input
 */
function checkMobileTelNumber(input) {
	if (!checkDataType(input))
		return;
	checkLengthTwo(8, 11, input, "移动电话");
}

/**
 * 验证手机格式
 */
function checkMobilePhoneNumber(inputObj) {
	var inputValue = inputObj.value;
	// if(inputValue==""||inputValue=="手机号码格式不正确!"){
	// $(inputObj).css("color","red");
	// $(inputObj).val("手机号码格式不正确!");
	// inputObj.focus();
	// return false;
	// }
	var reg = /^(13[0-9]{9})|(15[89][0-9]{8})|(18[0-9][0-9]{8})$/;
	if (reg.test(inputValue) == false) {
		$(inputObj).css("color", "red");
		$(inputObj).val("手机号码格式不正确!");
		// inputObj.focus();
		return false;
	} else {
		$(inputObj).css("color", "black");
		return true;
	}
}

function checkMobilePhoneNumber1(inputValue) {
	// if(inputValue==""||inputValue=="手机号码格式不正确!"){
	// return false;
	// }
	var reg = /^(13[0-9]{9})|(15[89][0-9]{8})|(18[0-9][0-9]{8})$/;
	if (reg.test(inputValue) == false) {
		return false;
	} else {
		return true;
	}
}

function isNotEmpty(inputObj) {
	var inputValue = inputObj.value;
	var title = $(inputObj).attr("title");
	if (inputValue == "" || inputValue == "手机号码不能为空!"
			|| inputValue == "身份证号码不能为空!") {
		$(inputObj).css("color", "red");
		$(inputObj).val(title);
		// $(inputObj).focus();
	}
}

/**
 * 当文本框为只读状态时,调用此方法,当点击退格键时,界面不会跳动
 */
function check() {
	if (window.event.keyCode == 8)
		window.event.keyCode = 0;
}

/**
 * 精确小数位
 * ValueString ：待处理数字
 * nAfterDotNum：截取长度，即精确几位小数
 */
function FormatAfterDotNumber(ValueString, nAfterDotNum) {
	var ValueString, nAfterDotNum;
	var resultStr, nTen;
	ValueString = "" + ValueString + "";
	strLen = ValueString.length;
	dotPos = ValueString.indexOf(".", 0);
	if (dotPos == -1) {
		resultStr = ValueString + ".";
		for (i = 0; i < nAfterDotNum; i++) {
			resultStr = resultStr + "0";
		}
		return resultStr;
	} else {
		if ((strLen - dotPos - 1) >= nAfterDotNum) {
			nAfter = dotPos + nAfterDotNum + 1;
			nTen = 1;
			for (j = 0; j < nAfterDotNum; j++) {
				nTen = nTen * 10;
			}
			resultStr = Math.round(parseFloat(ValueString) * nTen) / nTen;
			return resultStr;
		} else {
			resultStr = ValueString;
			for (i = 0; i < (nAfterDotNum - strLen + dotPos + 1); i++) {
				resultStr = resultStr + "0";
			}
			return resultStr;
		}
	}
}